package com.ry.novel.controller;

import com.ry.novel.model.dto.NewsInfo;
import com.ry.novel.model.resp.Result;
import com.ry.novel.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ry
 * @since 2022-05-01 16:22
 **/
@RequestMapping("/news")
@RestController
public class NewsController {
    @Autowired
    private NewsService newsService;

    @GetMapping("/queryNewsById")
    public Result<NewsInfo> queryNewsById(@RequestParam("id") Long id){
        NewsInfo newsInfo = newsService.queryNewsById(id);

        return Result.ok(newsInfo);
    }

    @GetMapping("/queryNewsByDateDesc")
    public Result<List<NewsInfo>> queryNewsByDateDesc(){
        List<NewsInfo> newsInfos = newsService.queryNewsByDateDesc();
        System.out.println(newsInfos);

        return Result.ok(newsInfos);
    }
}
